/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.example.services.impl;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import com.teknei.acabus.PersistenceException;
import com.teknei.acabus.ServiceException;
import com.teknei.acabus.core.entities.TableA;
import com.teknei.acabus.core.persistence.dao.TableADAO;
import com.teknei.acabus.example.services.TableAService;

/**
 * Session Bean implementation class TableAServiceBean
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 */
@Stateless
public class TableAServiceBean implements TableAService {

	@EJB
	private TableADAO daoTableA;
	
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableAService#findAll()
     */
    @Override
    public List<TableA> findAll() throws ServiceException{
    	try{
    		List<TableA> list = daoTableA.findAll();
    		return list;
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in findAll:"+e.getMessage(), e);
    	}
    }
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableAService#update(com.teknei.acabus.core.entities.TableA)
     */
    @Override
    public void update(TableA entity) throws ServiceException{
    	try{
    		daoTableA.update(entity);
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in update:"+e.getMessage(), e);
    	}
    }
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableAService#save(com.teknei.acabus.core.entities.TableA)
     */
    @Override
    public int save(TableA entity) throws ServiceException{
    	try{
    		TableA savedInstance = daoTableA.create(entity);
    		return savedInstance.getIdField();
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in save:"+e.getMessage(), e);
    	}
    }
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableAService#delete(com.teknei.acabus.core.entities.TableA)
     */
    @Override
    public void delete(TableA entity) throws ServiceException{
    	try{
    		daoTableA.delete(entity);
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in delete:"+e.getMessage(), e);
    	}
    }

	/**
	 * @return the daoTableA
	 */
	public TableADAO getDaoTableA() {
		return daoTableA;
	}

	/**
	 * @param daoTableA the daoTableA to set
	 */
	public void setDaoTableA(TableADAO daoTableA) {
		this.daoTableA = daoTableA;
	}

}
